class CreatePapers < ActiveRecord::Migration
  def self.up
    create_table :papers do |t|
      t.column :id, :int
      t.column :user_id, :integer
      t.column :title, :string
      t.column :author, :string
      t.column :publisher, :string
      t.column :publish_time, :datetime
      t.column :upload_time, :datetime
      t.column :ISBN, :string
      t.column :page_info, :string
      t.column :keyword1, :string
      t.column :keyword2, :string
      t.column :keyword3, :string
      t.column :download_url, :string
      t.column :abstract, :text
      t.column :file_type, :string
      t.column :paper_category_id, :int
      t.column :save_url, :string
      t.column :translation_url, :string
      t.column :ppt_url, :string
    end
    
    execute "alter table papers
               add constraint fk_papers_students 
               foreign key (user_id) references users(id)"
    
    execute "alter table papers
               add constraint fk_papers_paper_categories 
               foreign key (paper_category_id) references paper_categories(id)"
  end

  def self.down
    drop_table :papers
  end
end